]> git.r.bdr.sh - rbdr/super-polarity/blobdiff - Super Polarity/GameScreen.cs
Protoshow sprint.
[rbdr/super-polarity] / Super Polarity / GameScreen.cs
index 4404b16930419f27b898a6130a5200c878aa4cf3..783e3c12a61f57dc8a08e24634b32b142d077018 100644 (file)
@@ -4,6 +4,8 @@ using System.Linq;
 using System.Text;
 using Microsoft.Xna.Framework;
 using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Audio;
+using Microsoft.Xna.Framework.Media;
 using Microsoft.Xna.Framework.Input;
 
 namespace SuperPolarity
@@ -12,33 +14,196 @@ namespace SuperPolarity
     {
         public GameScreen(SuperPolarity newGame) : base(newGame) {}
 
+        protected List<BasicGenerator> Generators;
+
+        protected int LivesRate;
+        protected int CurrentLivesRate;
+        protected int BombRate;
+        protected int CurrentBombRate;
+        protected SoundEffect BombSound;
+        protected SoundEffect LifeSound;
+        
+        protected bool Flashing;
+
+        protected bool IsPaused;
+        protected Texture2D PauseScreen;
+
         public override void Initialize()
         {
+            Generators = new List<BasicGenerator>();
+
+            CurrentBombRate = 1;
+            BombRate = 6000;
+
+            LivesRate = 10000;
+            CurrentLivesRate = 1;
+
             InputController.RegisterEventForButton("changePolarity", Buttons.A);
             InputController.RegisterEventForKey("changePolarity", Keys.Z);
 
             InputController.RegisterEventForButton("shoot", Buttons.X);
             InputController.RegisterEventForKey("shoot", Keys.X);
+
+            InputController.Bind("pause", HandlePause);
+
+            PauseScreen = Game.Content.Load<Texture2D>("Graphics\\pause-screen");
+        }
+
+        protected void HandlePause(float value)
+        {
+            Console.WriteLine("Paused");
+            IsPaused = !IsPaused;
+
+            if (IsPaused)
+            {
+                MediaPlayer.Volume = 0.05f;
+            }
+            else
+            {
+                MediaPlayer.Volume = 1;
+            }
         }
 
         public override void LoadContent()
         {
-            Vector2 playerPosition = new Vector2(Game.GraphicsDevice.Viewport.TitleSafeArea.X, Game.GraphicsDevice.Viewport.TitleSafeArea.Y + Game.GraphicsDevice.Viewport.TitleSafeArea.Height / 2);
+            CreateGenerators();
+
+            Vector2 playerPosition = new Vector2(Game.GraphicsDevice.Viewport.TitleSafeArea.X + Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.TitleSafeArea.Y + Game.GraphicsDevice.Viewport.TitleSafeArea.Height / 2);
+
+            BombSound = Game.Content.Load<SoundEffect>("Sound\\bomb");
+            LifeSound = Game.Content.Load<SoundEffect>("Sound\\life");
 
             Renderer.CheckIn(ActorFactory.CreateMainShip(playerPosition));
-            Renderer.CheckIn(ActorFactory.CreateShip(Ship.Polarity.Positive, new Vector2(200, 200)));
-            Renderer.CheckIn(ActorFactory.CreateShip(Ship.Polarity.Negative, new Vector2(400, 200)));
+
+            Game.PlaySong("game");
+        }
+        
+        protected void CalculateBomb()
+        {
+            if (Game.Player.Score >= BombRate * CurrentBombRate)
+            {
+                ActorManager.Bomb();
+                Flashing = true;
+                BombSound.Play();
+                CurrentBombRate = CurrentBombRate + 1;
+            }
+        }
+
+        protected void CalculateLife()
+        {
+            if (Game.Player.Score >= LivesRate * CurrentLivesRate)
+            {
+                Game.Player.Lives = Game.Player.Lives + 1;
+                LifeSound.Play();
+                CurrentLivesRate = CurrentLivesRate + 1;
+            }
         }
 
         public override void Update(GameTime gameTime)
         {
-            InputController.UpdateInput();
+            CalculateBomb();
+            CalculateLife();
+            InputController.UpdateInput(IsPaused);
+            if (IsPaused)
+            {
+                return;
+            }
             ActorManager.Update(gameTime);
+
+            foreach (BasicGenerator generator in Generators)
+            {
+                generator.Update(gameTime);
+            }
         }
 
         public override void Draw(SpriteBatch spriteBatch)
         {
             Renderer.Draw(spriteBatch);
+            Game.Player.Draw(spriteBatch);
+
+            if (IsPaused)
+            {
+                spriteBatch.Draw(PauseScreen, new Vector2(0, 0), Color.White);
+            }
+
+            if (Flashing)
+            {
+                Game.GraphicsDevice.Clear(Color.Black);
+                Flashing = false;
+            }
+        }
+
+        protected void CreateGenerators()
+        {
+            // The basic ship generators.
+            var gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(-50, -50), BasicGenerator.Ships.Ship, 3000, 0);
+            Generators.Add(gen); 
+            
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0);
+            Generators.Add(gen); 
+            
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, -50), BasicGenerator.Ships.Ship, 3000, 0);
+            Generators.Add(gen);
+
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0);
+            Generators.Add(gen);
+
+            // After 1.5k liberate some sporadic Scouts, and add two more ship generators.
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 3000, 1500);
+            Generators.Add(gen);
+
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 1500);
+            Generators.Add(gen);
+
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500);
+            Generators.Add(gen);
+
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500);
+            Generators.Add(gen);
+
+
+            // After 3k add more scouts.
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Scout, 3000, 3000);
+            Generators.Add(gen);
+
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Scout, 3000, 5000);
+            Generators.Add(gen);
+
+            // After 5k release more ships and a cruiser.
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 1500, 5000);
+            Generators.Add(gen);
+
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 1500, 5000);
+            Generators.Add(gen);
+
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000);
+            Generators.Add(gen);
+
+            gen = new BasicGenerator();
+            gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000);
+            Generators.Add(gen);
+        }
+
+        public override void CleanUp()
+        {
+            base.CleanUp();
+            Generators.Clear();
+            InputController.Unbind("pause", HandlePause);
+            Renderer.Empty();
+            ActorManager.Empty();
         }
     }
 }